/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.partaljevic.tapestry.gambling.pages;

import com.partaljevic.gambling.Customer;
import com.partaljevic.gambling.Identifiable;
import com.partaljevic.gambling.Privilege;
import com.partaljevic.tapestry.gambling.service.Customers;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.util.EnumSelectModel;

/**
 *
 * @author Danilo
 */
public class EditCustomer {

    @Property
    private Customer currentCustomer;
    private String username;
    @Inject
    private Customers customers;
    @Inject
    private Messages messages;
    @Property
    private Privilege privilege;
    @InjectPage
    private AdminCustomer adminPage;

    void onActivate(long id) {
        currentCustomer = customers.retrieve(id);
    }

    public SelectModel getPrivileges() {
        return new EnumSelectModel(Privilege.class,messages);
    }
    Object onSubmitFromSaveForm(){
        customers.update(currentCustomer);
        adminPage.setMessage("Customer "+currentCustomer.showCustomer()+" saved!");
        return adminPage;
    }
    Object onSubmitFromDeleteForm(){
        customers.deleteCustomer(currentCustomer);
        adminPage.setMessage("Customer "+currentCustomer.showCustomer()+" deleted!");
        return adminPage;
    }
    long onPassivate() {
        return Identifiable.class.cast(currentCustomer).getID();
    }

    public String getUsername() {
        return currentCustomer.getUsername();
    }

    public void setUsername(String username) {
//        this.username = username;
    }

    
}
